//
//  UITabBarButton.swift
//  
//
//  Created by tangbl93 on 2021/1/11.
//

import UIKit

public extension UIControl {
    
    /// UITabBarButton class
    static var yx_UITabBarButtonClass:AnyClass? {
        return NSClassFromString("UITabBarButton")
    }
    
    /// UITabBarSwappableImageView class
    static var yx_UITabBarSwappableImageViewClass:AnyClass? {
        return NSClassFromString("UITabBarSwappableImageView")
    }
    
    /// UITabBarButtonLabel class
    static var yx_UITabBarButtonLabelClass:AnyClass? {
        return NSClassFromString("UITabBarButtonLabel")
    }
    
    /// is UITabBarButton instance
    var yx_isUITabBarButtonClass:Bool {
        guard let yx_UITabBarButtonClass = Self.yx_UITabBarButtonClass else { return false }
        return self.isKind(of: yx_UITabBarButtonClass)
    }
    
    /// get swappableImageView item
    var yx_swappableImageView:UIView? {
        if self.yx_isUITabBarButtonClass {} else { return nil }
        guard let yx_UITabBarSwappableImageViewClass = Self.yx_UITabBarSwappableImageViewClass else { return nil }
        
        for view in subviews {
            if view.isKind(of: yx_UITabBarSwappableImageViewClass) {
                return view
            }
        }
        
        return nil
    }
}
